#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
using namespace std;
typedef long long LL;
const int N = 110;
int arr[N];
int n;
int main()
{
    cin >> n;
    int x;
    for (int i = 0; i < n; i++) {
        scanf("%d", &x);
        arr[x]++;
    }
    LL sum = 0;
    for (int i = 1; i < 100; i++) {
        for (int j = i + 1; j <= 100; j++) {
            sum += (LL)(arr[j] * arr[i]) * (j - i);
        }
    }
    cout << sum << endl;
    return 0;
}